package controllers

import (
	"github.com/astaxie/beego"
	"xiegao/caches"
)

type AccessTokenController struct {
	beego.Controller
}

// @Title 获取一个Accesstoken
// @Description 获取一个Accesstoken
// @Success 200 {"code":200,"msg":"获取成功","data":{"token":"access token"}}
// @router /accesstoken [get]
func (self *AccessTokenController) Get() {
	AccessTokenSession := caches.CreateAccesstokenSession()
	accesstoken := AccessTokenSession.GetAccessToken()
	if len(accesstoken) == 0 {
		self.Data["json"] = map[string]interface{}{"code": 500, "msg": "获取失败"}
		self.ServeJSON()
		self.StopRun()
	}
	self.Data["json"] = map[string]interface{}{"code": 200, "msg": "获取成功", "data": map[string]interface{}{"data": accesstoken}}
	self.ServeJSON()
}
